﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.SessionState;





/// <summary>
/// Summary description for Class1
/// </summary>

    public class RepositorioTerceiro
    {
        private BD bd = new BD();
        
        public int pesquisaTerceiros(int codigo, String cnpj)
        {
            
            int total = 0;
            String sql = "Select * from tb_terceiros where terc_cod = '" + codigo + "' and terc_cnpj= '" + cnpj + "'";
            total = bd.totalRegistros(sql);
            return total;
        }

        public Terceiro carregaSession(int codigo, String cnpj)
        {
            Terceiro terceiro = new Terceiro();
            String sql = "Select * from tb_terceiros where terc_cod = '" + codigo + "' and terc_cnpj= '" + cnpj + "'";
            using (SqlConnection conexao = new SqlConnection(bd.strConnection))
            {
                conexao.Open();
                SqlCommand comando = new SqlCommand(sql, conexao);
                SqlDataReader dr = comando.ExecuteReader();

                while (dr.Read())
                {
                    terceiro.End_av_rua = dr["End_av_rua"].ToString();
                    terceiro.End_bairro = dr["End_bairro"].ToString();
                    terceiro.End_cep = dr["End_cep"].ToString();
                    terceiro.End_cidade = dr["End_cidade"].ToString();
                    terceiro.End_complemento = dr["End_complemento"].ToString();
                    terceiro.End_num = int.Parse(dr["End_num"].ToString());
                    terceiro.End_uf = dr["End_uf"].ToString();
                    terceiro.Terc_nome = dr["terc_nome"].ToString();
                    terceiro.Terc_cod = int.Parse(dr["terc_cod"].ToString());
                    terceiro.Terc_email = dr["terc_email"].ToString();
                    terceiro.Terc_fone = dr["terc_fone"].ToString();

                    
                }
            }
            return terceiro;
        }


}

